Screen (from Node)¶
The screen on which every other node renders.
Options¶
- program - The blessed
Program
to be associated with. Will be automatically instantiated if none is provided. - smartCSR - Attempt to perform CSR optimization on all possible elements (not just full-width ones, elements with uniform cells to their sides). This is known to cause flickering with elements that are not full-width, however, it is more optimal for terminal rendering.
- fastCSR - Do CSR on any element within 20 cols of the screen edge on either side. Faster than
smartCSR
, but may cause flickering depending on what is on each side of the element. - useBCE - Attempt to perform
back_color_erase
optimizations for terminals that support it. It will also work with terminals that don't support it, but only on lines with the default background color. As it stands with the current implementation, it's uncertain how much terminal performance this adds at the cost of overhead within node. - resizeTimeout - Amount of time (in ms) to redraw the screen after the terminal is resized (Default: 300).
- tabSize - The width of tabs within an element's content.
- autoPadding - Automatically position child elements with border and padding in mind (NOTE: this is a recommended option. It may become default in the future).
- cursor.artificial - Have blessed draw a custom cursor and hide the terminal cursor (experimental).
- cursor.shape - Shape of the cursor. Can be: block, underline, or line.
- cursor.blink - Whether the cursor blinks.
- cursor.color - Color of the color. Accepts any valid color value (
null
is default). - log - Create a log file. See
log
method. - dump - Dump all output and input to desired file. Can be used together with
log
option if set as a boolean. - debug - Debug mode. Enables usage of the
debug
method. Also creates a debug console which will display when pressing F12. It will display all log and debug messages. - ignoreLocked - Array of keys in their full format (e.g.
C-c
) to ignore when keys are locked or grabbed. Useful for creating a key that will always exit no matter whether the keys are locked. -
dockBorders - Automatically "dock" borders with other elements instead of overlapping, depending on position (experimental). For example: These border-overlapped elements:
┌─────────┌─────────┐ │ box1 │ box2 │ └─────────└─────────┘
Become:
┌─────────┬─────────┐ │ box1 │ box2 │ └─────────┴─────────┘
-
ignoreDockContrast - Normally, dockable borders will not dock if the colors or attributes are different. This option will allow them to dock regardless. It may produce some odd looking multi-colored borders though.
- fullUnicode - Allow for rendering of East Asian double-width characters, utf-16 surrogate pairs, and unicode combining characters. This allows you to display text above the basic multilingual plane. This is behind an option because it may affect performance slightly negatively. Without this option enabled, all double-width, surrogate pair, and combining characters will be replaced by
'??'
,'?'
,''
respectively. (NOTE: iTerm2 cannot display combining characters properly. Blessed simply removes them from an element's content if iTerm2 is detected). - sendFocus - Send focus events after mouse is enabled.
- warnings - Display warnings (such as the output not being a TTY, similar to ncurses).
- forceUnicode - Force blessed to use unicode even if it is not detected via terminfo, env variables, or windows code page. If value is
true
unicode is forced. If value isfalse
non-unicode is forced (default:null
). - input/output - Input and output streams.
process.stdin
/process.stdout
by default, however, it could be anet.Socket
if you want to make a program that runs over telnet or something of that nature. - terminal -
TERM
name used for terminfo parsing. The$TERM
env variable is used by default. - title - Set the terminal window title if possible.
Properties¶
- Inherits all from Node.
- program - The blessed Program object.
- tput - The blessed Tput object (only available if you passed
tput: true
to the Program constructor.) - focused - Top of the focus history stack.
- width - Width of the screen (same as
program.cols
). - height - Height of the screen (same as
program.rows
). - cols - Same as
screen.width
. - rows - Same as
screen.height
. - left - Relative left offset, always zero.
- right - Relative right offset, always zero.
- top - Relative top offset, always zero.
- bottom - Relative bottom offset, always zero.
- aleft - Absolute left offset, always zero.
- aright - Absolute right offset, always zero.
- atop - Absolute top offset, always zero.
- abottom - Absolute bottom offset, always zero.
- grabKeys - Whether the focused element grabs all keypresses.
- lockKeys - Prevent keypresses from being received by any element.
- hover - The currently hovered element. Only set if mouse events are bound.
- terminal - Set or get terminal name.
Set
callsscreen.setTerminal()
internally. - title - Set or get window title.
Events¶
- Inherits all from Node.
- resize - Received on screen resize.
- mouse - Received on mouse events.
- keypress - Received on key events.
- element [name] - Global events received for all elements.
- key [name] - Received on key event for [name].
- focus, blur - Received when the terminal window focuses/blurs. Requires a terminal supporting the focus protocol and focus needs to be passed to program.enableMouse().
- prerender - Received before render.
- render - Received on render.
- warning - Received when blessed notices something untoward (output is not a tty, terminfo not found, etc).
- destroy - Received when the screen is destroyed (only useful when using multiple screens).
Methods¶
- Inherits all from Node.
- log(msg, ...) - Write string to the log file if one was created.
- debug(msg, ...) - Same as the log method, but only gets called if the
debug
option was set. - alloc() - Allocate a new pending screen buffer and a new output screen buffer.
- realloc() - Reallocate the screen buffers and clear the screen.
- draw(start, end) - Draw the screen based on the contents of the screen buffer.
- render() - Render all child elements, writing all data to the screen buffer and drawing the screen.
- clearRegion(x1, x2, y1, y2) - Clear any region on the screen.
- fillRegion(attr, ch, x1, x2, y1, y2) - Fill any region with a character of a certain attribute.
- focusOffset(offset) - Focus element by offset of focusable elements.
- focusPrevious() - Focus previous element in the index.
- focusNext() - Focus next element in the index.
- focusPush(element) - Push element on the focus stack (equivalent to
screen.focused = el
). - focusPop() - Pop element off the focus stack.
- saveFocus() - Save the focused element.
- restoreFocus() - Restore the saved focused element.
- rewindFocus() - "Rewind" focus to the last visible and attached element.
- key(name, listener) - Bind a keypress listener for a specific key.
- onceKey(name, listener) - Bind a keypress listener for a specific key once.
- unkey(name, listener) - Remove a keypress listener for a specific key.
- spawn(file, args, options) - Spawn a process in the foreground, return to blessed app after exit.
- exec(file, args, options, callback) - Spawn a process in the foreground, return to blessed app after exit. Executes callback on error or exit.
- readEditor([options], callback) - Read data from text editor.
- setEffects(el, fel, over, out, effects, temp) - Set effects based on two events and attributes.
- insertLine(n, y, top, bottom) - Insert a line into the screen (using csr: this bypasses the output buffer).
- deleteLine(n, y, top, bottom) - Delete a line from the screen (using csr: this bypasses the output buffer).
- insertBottom(top, bottom) - Insert a line at the bottom of the screen.
- insertTop(top, bottom) - Insert a line at the top of the screen.
- deleteBottom(top, bottom) - Delete a line at the bottom of the screen.
- deleteTop(top, bottom) - Delete a line at the top of the screen.
- enableMouse([el]) - Enable mouse events for the screen and optionally an element (automatically called when a form of on('mouse') is bound).
- enableKeys([el]) - Enable keypress events for the screen and optionally an element (automatically called when a form of on('keypress') is bound).
- enableInput([el]) - Enable key and mouse events. Calls bot enableMouse and enableKeys.
- copyToClipboard(text) - Attempt to copy text to clipboard using iTerm2's proprietary sequence. Returns true if successful.
- cursorShape(shape, blink) - Attempt to change cursor shape. Will not work in all terminals (see artificial cursors for a solution to this). Returns true if successful.
- cursorColor(color) - Attempt to change cursor color. Returns true if successful.
- cursorReset() - Attempt to reset cursor. Returns true if successful.
- screenshot([xi, xl, yi, yl]) - Take an SGR screenshot of the screen within the region. Returns a string containing only characters and SGR codes. Can be displayed by simply echoing it in a terminal.
- destroy() - Destroy the screen object and remove it from the global list. Also remove all global events relevant to the screen object. If all screen objects are destroyed, the node process is essentially reset to its initial state.
- setTerminal(term) - Reset the terminal to
term
. Reloads terminfo.
Last update: February 22, 2020